<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<image class="default-avatar" src="@/static/images/logo.png" mode="aspectFill"></image>
					</view>
					<image v-if="avatar" @click="handleToAvatar" src="@/static/images/logo.png" class="cu-avatar xl round"
						mode="aspectFill">
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" @click="handleToInfo" class="user-info">
						<view class="u_title">
							用户名：{{ name }}
						</view>
					</view>
				</view>
				<!-- <view @click="handleToInfo" class="flex align-center">
					<text>个人信息</text>
					<view class="iconfont icon-right"></view>
				</view> -->
			</view>
		</view>

		<view class="content-section">
			<!-- <view class="mine-actions grid col-4 text-center">
				<view class="action-item" @click="device">
					<u-image width="40px" height="40px"
						:src='"https://img-blog.csdnimg.cn/direct/2370e543778e4eb29cebd994321c83a0.png"' />
					<text class="text">我的设备</text>
				</view>
				<view class="action-item" @click="authentication">
					<u-image width="40px" height="40px"
						:src='"https://img-blog.csdnimg.cn/direct/7e6e3bd562134ec9a18aeef812154693.png"' />
					<text class="text">身份认证</text>
				</view>

				<view class="action-item" @click="updatePassword">
					<u-image width="40px" height="40px"
						:src='"https://img-blog.csdnimg.cn/direct/8bfdd7af0b2d4c2bb9380ebee6dce761.png"' />
					<text class="text">修改密码</text>
				</view>

				<view class="action-item" @click="handleBuilding">
					<u-image width="40px" height="40px"
						:src='"https://img-blog.csdnimg.cn/direct/1472efe49d854803b5a0f7afc950ce84.png"' />
					<text class="text">使用指南</text>
				</view>
			</view> -->

			<view class="menu-list">
				<!-- <view class="list-cell list-cell-arrow" @click="handleToInfo">
					<view class="menu-item-box">
						<u-image width="40px" height="40px" :src='"@/static/images/tabbar/geren.png"' />
						<view class="tit">个人信息</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleToEditInfo">
					<view class="menu-item-box">
						<u-image width="40px" height="40px" :src='"@/static/images/tabbar/bianji.png"' />
						<view class="tit">编辑资料</view>
					</view>
				</view> -->
			<!-- 	<view class="list-cell list-cell-arrow" @click="handleHelp">
					<view class="menu-item-box">
						<u-image width="40px" height="40px" :src='"@/static/images/tabbar/changjian.png"' />
						<view class="tit">常见问题</view>
					</view>
				</view> -->
				<view class="list-cell list-cell-arrow" @click="handleAbout">
					<view class="menu-item-box">
						<u-image width="40px" height="40px" :src='"@/static/images/tabbar/changjian.png"' />
						<view class="tit">关于我们</view>
					</view>
				</view>
				
				<!-- 添加退出登录按钮 -->
				<view class="list-cell logout-cell" @click="handleLogout">
					<view class="menu-item-box">
						<u-image width="30px" height="30px" :src='"@/static/images/tabbar/tuichu.png"' />
						<view class="tit">退出登录</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {
		checkPermi,
		checkRole
	} from "@/utils/permission"; // 权限判断函数

	export default {
		data() {
			return {
				name: this.$store.state.user.name,
				version: getApp().globalData.config.appInfo.version
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		methods: {
			checkPermi,
			checkRole,
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			authentication() {
				this.$tab.navigateTo('/pages/mine/uploadinfo/index')
			},
			updatePassword() {
				this.$tab.navigateTo('/pages/mine/updatepwd/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleHelp() {
				this.$tab.navigateTo('/pages/mine/help/index')
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			device() {
				wx.switchTab({
					url: '/pages/records/list'
				})
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			},
			shangbao() {
				this.$tab.navigateTo('/pages/mine/fankui')
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f6f7;
	}
	
	.default-avatar {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
	
	.logout-cell {
		margin-top: 20px;
		background-color: white;
		border-radius: 8px;
		
		.menu-item-box {
			display: flex;
			align-items: center;
			padding: 15px;
			
			.tit {
				color: #f56c6c;
			}
		}
	}
	
	.menu-item-box{
		.tit{
			text-indent: 10px;
		}
	}
	.content-section .action-item .u-transition {
		align-items: center;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #4B71F7;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {
			position: relative;
			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}
	}
</style>